package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author:hx
 * @DateTime:2022/11/8 14:13
 * @Description:
 */
@RestController
@RequestMapping("/admin/hospital")
public class AdminHospitalController {

    @Autowired
    private HospitalService hospitalService;

    /**
     * @Description 分页查询医院信息
     * @param pageNum:
     * @param pageSize:
     * @param hospitalQueryVo:
     * @return: com.atguigu.yygh.common.result.R
     */
    @PostMapping("/findPage/{pageNum}/{pageSize}")
    public R findPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestBody HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page = hospitalService.findPage(pageNum,pageSize,hospitalQueryVo);
        return R.ok().data("total",page.getTotalElements()).data("items",page.getContent());
    }

    /**
     * @Description 更新医院状态
     * @param id:
     * @param status:
     * @return: com.atguigu.yygh.common.result.R
     */
    @PutMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable String id,@PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }

    @GetMapping("/getHospById/{id}")
    public R getHospById(@PathVariable String id){
        Map<String,Object> hospital = hospitalService.getHospById(id);
        return R.ok().data("hospital",hospital);
    }
}
